<?php
require_once ROOT_PATH . '/lib/models/hrfunct/EmpInfo.php';
require_once ROOT_PATH . '/plugins/PlugInFactoryException.php';

$baseURL = './CentralController.php?skillMatrixcode=SkillMatrix'; 
$skillGroup = $records;

$date = date("Y-m-d");  
if($skillGroup['skill_group_id']==NULL){
	$action = "SaveGroup";
	$title = "Add new group";
}
else{ 
	$action = "EditGroup";
	$title = "Update group";
}
?>
<script type="text/javascript" src="../../scripts/archive.js"></script>
<?php include ROOT_PATH."/lib/common/calendar.php"; ?>
<script type="text/javascript">



function returnAdd() {
		location.href = '<?php echo $baseURL;?>&action=ViewAddQuestion&surveyid=<?php echo $skillGroup['skill_group_id'];?>';
}
function returnDelete() {
		var check = false;
		with (document.frmQuestion) {
			for (var i=0; i < elements.length; i++) {
				if ((elements[i].type == 'checkbox') && (elements[i].checked == true)){
					check = true;
					break;
				}
			}

			if (check) {
				document.frmQuestion.action= "<?php echo $_SERVER['PHP_SELF']; ?>?surveycode=Surveys&action=DeleteQuestions";
				document.frmQuestion.submit();
			} else {
				alert("<?php echo $lang_Error_SelectAtLeastOneRecordToDelete; ?>");
			}
		}
	}
	
function addSave() {
	if(validate()==true)
		document.frmSurveys.submit();
	else
		return false;
}

function checkAll(field)
{
	if(document.frmSurveys.checkall.checked == false){
		for (i = 0; i < field.length; i++)
			field[i].checked = false ;
	}else{
		for (i = 0; i < field.length; i++)
		field[i].checked = true ;
	}
	
}

function validate() {
	var skillgroupname = document.getElementById('skill_group_name').value;
	var skillgrouptype = document.getElementById('skill_group_type').value;
	errFlag=false;
	errors = new Array();
	if(skillgroupname.length ==0){
		errors[errors.length]= "Skill group name can not be null!";
		errFlag=true;
	}
	
	if(!skillgrouptype){
		errors[errors.lengt+1]= "You have to select at least 1 skill group type";
		errFlag=true;
	}
	
	if (errFlag) {
		errStr="<?php echo $lang_Common_EncounteredTheFollowingProblems; ?>\n";
		for (i in errors) {
			errStr+=" - "+errors[i]+"\n";
		}
		alert(errStr);
		return false;
	}
	return true;
}

//YAHOO.OrangeHRM.container.init();
/*
YAHOO.util.Event.addListener($("frmSurveys"), "submit", viewProjectReport);
*/


</script>

<h2>
<?php echo $title; ?>
<hr/>
</h2>
<div id="status"></div>
<?php if (isset($_GET['message'])) {

		$expString  = $_GET['message'];
?>
		<font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
<?php echo $expString; ?>
		</font>
<?php }	?>
<form name="frmSurveys" id="frmSurveys" method="post"  action="<?php echo $_SERVER['PHP_SELF']; ?>?skillMatrixcode=SkillMatrix&action=<?php echo $action; ?>">
<input type="hidden" name="txtId" value="<?php echo $skillGroup['skill_group_id']; ?>" >
<table border="0" cellpadding="2" cellspacing="0">
	<thead>
		<tr>
			<th class="tableTopLeft"></th>
	    	<th class="tableTopMiddle" ></th>
	    	<th class="tableTopMiddle" ></th>
			<th class="tableTopRight"></th>
		</tr>
	</thead>
	<tbody>
	<tr>
			<td class="tableMiddleLeft"></td>
			<td ><?php echo "Group Name"; ?></td>			
			<td >
				<input type="text" name ="skill_group_name" id ="skill_group_name" value=""/>				
			</td>
			<td class="tableMiddleRight"></td>
	</tr>
	<tr>
			<td class="tableMiddleLeft"></td>
			<td ><?php echo "Group type"; ?></td>			
			<td >
				<select name="skill_group_type[]" id="skill_group_type" multiple>					
					<option value="1">Developer</option>
					<option value="2">QA</option>
				</select>
								
			</td>
			<td class="tableMiddleRight"></td>
	</tr>
	
	<tr>
			<td class="tableMiddleLeft"></td>
			<td ></td>
			<td >
				<input type="image"  onclick="return addSave();" name="btnSave" alt="Save"
					   src="../../themes/beyondT/pictures/btn_save.gif" />
			</td>
			<td class="tableMiddleRight"></td>
	</tr>
		
	</tbody>
	<tfoot>
	  	<tr>
			<td class="tableBottomLeft"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomMiddle"></td>
			<td class="tableBottomRight"></td>
		</tr>
  	</tfoot>
</table>
</form>

